<html>
<head><meta charset="utf-8"><title>const_evaluatable: type alias · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html">const_evaluatable: type alias</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224165538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224165538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224165538">(Jan 27 2021 at 10:59)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, const_evaluatable_checked)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">type</span> <span class="nc">Alias</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Alias</span><span class="o">&lt;</span><span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">M</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">M</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="224165547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224165547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224165547">(Jan 27 2021 at 10:59)</a>:</h4>
<p>uwu</p>
<div class="codehilite"><pre><span></span><code>error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:516:17: expected type for `T/#0` (T/0) but found Const(Const { ty: usize, val: Param(M/#0) }) when substituting, substs=[Const { ty: usize, val: Param(M/#0) }]

thread &#39;rustc&#39; panicked at &#39;Box&lt;Any&gt;&#39;, /rustc/d1aed50ab81df3140977c610c5a7d00f36dc519f/compiler/rustc_errors/src/lib.rs:904:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&amp;template=ice.md

note: rustc 1.51.0-nightly (d1aed50ab 2021-01-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden
</code></pre></div>



<a name="224165761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224165761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224165761">(Jan 27 2021 at 11:01)</a>:</h4>
<p>the issue is here <a href="https://github.com/rust-lang/rust/blob/742c972c4f92a8f213d05b82ba04797f251f125a/compiler/rustc_typeck/src/collect.rs#L2109">https://github.com/rust-lang/rust/blob/742c972c4f92a8f213d05b82ba04797f251f125a/compiler/rustc_typeck/src/collect.rs#L2109</a></p>



<a name="224166082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224166082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224166082">(Jan 27 2021 at 11:04)</a>:</h4>
<p>we call <code>type_of</code> instead of <code>AstConv::ast_ty_to_ty</code></p>



<a name="224166167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224166167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224166167">(Jan 27 2021 at 11:05)</a>:</h4>
<p><code>type_of(ty_alias_def_id)</code> does not substitute the used generic arguments though, so while collecting the <code>ConstEvaluatable</code> predicates for <code>foo</code></p>



<a name="224166217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224166217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224166217">(Jan 27 2021 at 11:05)</a>:</h4>
<p>we look at <code>Alias&lt;T, N&gt;</code> instead of <code>Alias&lt;u32, M&gt;</code></p>



<a name="224166345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224166345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224166345">(Jan 27 2021 at 11:07)</a>:</h4>
<p>and end up with a const evaluatable predicate with <code>N</code> and <code>T</code> in its substs which is bogus</p>



<a name="224168688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224168688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224168688">(Jan 27 2021 at 11:33)</a>:</h4>
<p>looking at some of the slightly more complex tests we currently have for <code>const_evaluatable_checked</code> and after mentoring <span class="user-mention" data-user-id="326176">@Boxy</span> for <a href="https://github.com/rust-lang/rust/issues/81426">#81426</a> it felt to me like it probably causes more harm than good to look into type aliases. imo we should just stop looking into type aliases at all in <code>const_evaluatable_predicates_of</code> instead of fixing this bug ^^</p>



<a name="224169398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224169398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224169398">(Jan 27 2021 at 11:42)</a>:</h4>
<p>i think it can feel inconsistent that <code>foo</code> needs a bound here while <code>bar</code> does not <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, const_evaluatable_checked)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features)]</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Output</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Q</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Q</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">Q</span><span class="o">&lt;</span><span class="p">{</span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">}</span><span class="o">&gt;</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Output</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Q</span><span class="o">&lt;</span><span class="p">{</span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">}</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="o">&lt;</span><span class="n">Q</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Foo</span><span class="o">&gt;</span>::<span class="n">Output</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Q</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">type</span> <span class="nc">Bar</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Q</span><span class="o">&lt;</span><span class="p">{</span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">}</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">bar</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Bar</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Q</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="224169414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224169414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224169414">(Jan 27 2021 at 11:42)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="124288">@oli</span> ^^</p>



<a name="224170552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224170552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224170552">(Jan 27 2021 at 11:57)</a>:</h4>
<p>I think this is like when we have bounds on the struct declaration (not just with const generics), then all functions using this struct also need these bounds, even if we could just automatically create the bounds, because you already need to fulfill them for the struct anyway</p>



<a name="224170572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224170572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224170572">(Jan 27 2021 at 11:57)</a>:</h4>
<p>so we should fix this together with regular trait bounds</p>



<a name="224171568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224171568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224171568">(Jan 27 2021 at 12:06)</a>:</h4>
<p>does that mean you agree with us stopping to looking into type aliases for now? <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="224171656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224171656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224171656">(Jan 27 2021 at 12:08)</a>:</h4>
<p>idk what regular trait bounds do... do whatever they do</p>



<a name="224171763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/const_evaluatable%3A%20type%20alias/near/224171763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias.html#224171763">(Jan 27 2021 at 12:09)</a>:</h4>
<p><span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>